﻿
//	------------------------------------------------------------------------------
//                                       _                          
//              _ __ ___   ___ _ __ ___ | |__  _ __ __ _ _ __   ___ 
//             | '_ ` _ \ / _ \ '_ ` _ \| '_ \| '__/ _` | '_ \ / _ \
//             | | | | | |  __/ | | | | | |_) | | | (_| | | | |  __/
//             |_| |_| |_|\___|_| |_| |_|_.__/|_|  \__,_|_| |_|\___|
//                                                     
//	------------------------------------------------------------------------------

#region - License -
//
//	------------------------------------------------------------------------------                                                   
//	         Copyright (c) 2010 Peter Vyvey (peter.vyvey@chiliware.be)
//	------------------------------------------------------------------------------
//
//
//	This file is part of CHILIWARE MEMBRANE.
//
//	CHILIWARE MEMBRANE is free software: you can redistribute it and/or modify
//	it under the terms of the GNU Lesser General Public License as published by
//	the Free Software Foundation, either version 3 of the License, or
//	(at your option) any later version.
//
//	CHILIWARE MEMBRANE is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU Lesser General Public License for more details.
//
//	You should have received a copy of the GNU Lesser General Public License
//	along with CHILIWARE MEMBRANE.  If not, see <http://www.gnu.org/licenses/>.
//
//
#endregion

#region - Changes -

//	peter.vyvey@chiliware.be     2010-08-09      Created.

#endregion

#region - Using -

using System;

#endregion

namespace Chiliware.Membrane.Extension
{
	#region - CatchInvalidArgumentExtension -

	/// <summary>
	/// Extension methods to handle method argument validation.
	/// </summary>
	public static class CatchInvalidArgumentExtension
	{
		#region - Public static methods -

		/// <summary>
		/// Checks if a given argument object is null. If so throws an ArgumentNullException.
		/// </summary>
		/// <param argumentName="argument">The argument object to check.</param>
		/// <param argumentName="argumentName">The argument name to be included in the exception message.</param>
		/// <exception cref="ArgumentNullException">The <paramref argumentName="argumentName"/> [is|are] not provided.</exception>
		public static void CatchNullArgument(this object argument, string argumentName)
		{
			if (argument.IsDefault())
			{
				string verb = argumentName.EndsWith("s") && !argumentName.EndsWith("is") ? "are" : "is";
				string message = string.Format("The {0} {1} not provided.", argumentName, verb);

				throw new ArgumentNullException(argumentName, message);
			}
		}

		/// <summary>
		/// Checks if a given argument string is empty. If so throws an ArgumentException.
		/// The null argument is not considered empty.
		/// </summary>
		/// <param argumentName="argument">The argument string to check.</param>
		/// <param argumentName="argumentName">The argument name to be included in the exception message.</param>
		/// <exception cref="ArgumentNullException">The <paramref argumentName="argumentName"/> [is|are] empty.</exception>
		public static void CatchNullOrEmptyArgument(this string argument, string argumentName)
		{
			if (string.IsNullOrEmpty(argument))
			{
				string verb = argumentName.EndsWith("s") && !argumentName.EndsWith("is") ? "are" : "is";
				string message = string.Format("The {0} {1} empty.", argumentName, verb);

				throw new ArgumentException(message, argumentName);
			}
		}

		#endregion
	}

	#endregion
}
